package Array;

import org.junit.Test;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: Array
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-11-26  17:19
 * @Description: TODO
 * @Version: 1.0
 */
public class 最小覆盖子串76 {

    public String minWindow(String s, String t) {
        String result = "";
        if (s.length() < t.length()) {
            return result;
        }
        int left = 0;
        for (int right = 0; right < s.length(); right++) {
            String tmp = s.substring(left, right + 1);
            // 检查是否包含这个元素
            while (checkWindow(tmp, t)) {
                if (result == "") {
                    result = s.substring(left, right + 1);
                } else {
                    if (right - left + 1 < result.length()) {
                        result = s.substring(left, right + 1);
                    }
                }
                // 如果包含
                left++;
                tmp = tmp.substring(1);
            }
        }
        return result;
    }

    private boolean checkWindow(String tmp, String t) {
        for (int i = 0; i < t.length(); i++) {
            if (tmp.indexOf(t.charAt(i)) == -1) {
                return false;
            }
        }
        return true;
    }

    @Test
    public void test() {
        String s = minWindow("aa", "aa");
        System.out.println(s);
    }
}
